<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<script type="text/javascript" src="/${initParam.context_root }/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
function search(){
	var chk = $(":radio[name=whatSearch]:checked").val();
	var content = $("#searchForm").val();
	$("#form1").attr({"action":"/${initParam.context_root}/selectBoardByPage.do?page=1&contentGroup=0&"+chk+"="+content,"method":"post"}).submit();
}
</script>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>글 목록</h1>
<body>
<!-- 
<form id="form1">
	제목 : <input type="radio" name="whatSearch" value="title">
	내용 : <input type="radio" name="whatSearch" value="content">
	검색 : <input type="text" id="searchForm">
	<input type="button" value="검색" onclick="search()">
</form>
 -->
<a href="/${initParam.context_root}/selectBoardByPage.do?page=1&contentGroup=0">전체 글</a> &nbsp; <a href="/${initParam.context_root}/selectBoardByPage.do?page=1&contentGroup=2">자유글 </a> &nbsp; <a href="/${initParam.context_root}/selectBoardByPage.do?page=1&contentGroup=3">제품 문의</a> &nbsp; <a href="/${initParam.context_root}/selectBoardByPage.do?page=1&contentGroup=4">후기</a>

<form action="/${initParam.context_root}/selectBoardByPage.do" method="post" enctype="multipart/form-data">
<input type="hidden" name="page" value="1"	>
<c:choose>	
	<c:when test="${not empty sessionScope}">
		<table border="2" cellspacing="0" width="850" cellpadding="10px" bgcolor="#fffafa">
			<tr bgcolor="lightblue">
				<td colspan="5">
					<label> 자유 글 <input type="radio" value="2" name="contentGroup" checked="checked"></label> &nbsp; &nbsp;
					<label>제품 문의 <input type="radio" value="3" name="contentGroup"></label> &nbsp; &nbsp; 
					<label>소셜 쇼핑 후기 <input type="radio" value="4" name="contentGroup"></label> &nbsp; &nbsp; 
				</td>
			</tr>
			<tr>
				<td colspan="5">
				&nbsp;	제목 : <input type="text" name="title" size="120">
				</td>
			</tr>
			<tr>
				<td colspan="5"><input type="file" name="upfile" value="사진 등록"></td>
			</tr>
			<tr>
				<td colspan="4">
					<textarea rows="7" cols="100" name="content"></textarea>
				</td>
				<td>
					<input type="submit" value="작성">
				</td>
			</tr>
		</table>
	</c:when>
	<c:otherwise>
		<font color="red">비회원은 읽기만 가능합니다.</font>
	</c:otherwise>
</c:choose>
		<hr>
	<table border="2" cellspacing="0" width="850" cellpadding="10px" bgcolor="#fffafa">
		<tr bgcolor="lightblue">
			<td width="15">번호</td>
			<td width="75">사진</td>
			<td>제목</td>
			<td width="50">작성자</td>
			<td width="30">작성일</td>
			<td width="50">조회수</td>
		</tr>
		<c:forEach items="${requestScope.boardAllList.list}" var="bal" >
		<tr>
			<td>
				${bal.no}
			</td>
			<td>
			<c:if test="${not empty bal.pictureName}">
					<img src="/${initParam.context_root }/upfile/${bal.pictureName}" width="75" height="75"/>
				</c:if>
			</td>
			<td valign="middle">
			<c:if test="${bal.relevel!=0}">
			<c:forEach begin="1" end="${bal.relevel}"> &nbsp; &nbsp;  
			</c:forEach>
				↘
			</c:if>
				<a href="/${initParam.context_root}/boardContent.do?&page=${requestScope.paging.pagingDTO.currentPage}&no=${bal.no}&contentGroup=${bal.contentGroup}">
				${bal.title}
				</a>
			</td>
			<td>
			<c:choose>
				<c:when test="${bal.boardMemberId!=null }">
					${bal.boardMemberId}
				</c:when>
				<c:when test="${bal.companyMemberId!=null }">
					${bal.companyMemberId}
				</c:when>
				<c:when test="${bal.adminMemberId!=null }">
					${bal.adminMemberId}
				</c:when>
				<c:otherwise>
					손님
				</c:otherwise>			
			</c:choose>
			</td>
			<td>
				${bal.writedate}
			</td>
			<td>
				${bal.viewcount}
			</td>
		</tr>
		</c:forEach>
	</table>
</form>
<hr>
<c:choose>
	<c:when test="${requestScope.paging.pagingDTO.previousPageGroup==true}">
		<a href="/${initParam.context_root}/selectBoardByPage.do?page=${requestScope.paging.pagingDTO.startPageOfPageGroup-1}&contentGroup=${requestScope.contentGroup}">◀</a>
	</c:when>
	<c:otherwise>◁</c:otherwise>
</c:choose>

<c:forEach begin="${requestScope.paging.pagingDTO.startPageOfPageGroup}" end="${requestScope.paging.pagingDTO.endPageOfPageGroup}" var="i">
	<c:choose>
		<c:when test="${i eq requestScope.paging.pagingDTO.currentPage}">
			${i}
		</c:when>
		<c:otherwise>
			<a href="/${initParam.context_root}/selectBoardByPage.do?page=${i}&contentGroup=${requestScope.contentGroup}">${i}</a>
		</c:otherwise>
	</c:choose>
</c:forEach>

<c:choose>
	<c:when test="${requestScope.paging.pagingDTO.nextPageGroup==true}">
		<a href="/${initParam.context_root}/selectBoardByPage.do?page=${requestScope.paging.pagingDTO.endPageOfPageGroup+1}&contentGroup=${requestScope.contentGroup}">▶</a>
	</c:when>
	<c:otherwise>▷</c:otherwise>
</c:choose>
</body>
</html>